{% extends 'oscar/dashboard/layout.html' %}
{% load sorting_tags %}
{% load i18n %}

{% block title %}
    {% trans "Partners" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
        </li>
        <li>
            <a href="{% url 'dashboard:partner-list' %}">{% trans "Partners" %}</a>
        </li>
        <li class="active">{{ partner.name }}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header">
        <div class="btn-group pull-right">
            <a class="btn btn-lg btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
                <i class="icon-plus"></i>
                {% trans 'Link a user' %}
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li><a href="{% url 'dashboard:partner-user-create' partner_pk=partner.pk %}" >{% trans "Link a new user" %}</a></li>
                <li><a href="{% url 'dashboard:partner-user-select' partner_pk=partner.pk %}" >{% trans "Link an existing user" %}</a></li>
            </ul>
        </div>
        <h1>{% trans "Manage users" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    {% if users %}
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>{% trans 'Email' %}</th>
                    <th>{% trans 'First name' %}</th>
                    <th>{% trans 'Last name' %}</th>
                    <th>&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                    <tr>
                        <td><a href="{% url 'dashboard:partner-user-update' partner_pk=partner.pk user_pk=user.id %}">{{ user.email }}</a></td>
                        <td>{{ user.first_name|default:"-" }}</td>
                        <td>{{ user.last_name|default:"-" }}</td>
                        <td>
                            <form action="{% url 'dashboard:partner-user-unlink' partner_pk=partner.id user_pkuser.id %}" method="post">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-danger" data-loading-text="{% trans 'Unlinking...' %}">{% trans 'Unlink user' %}</button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>{% trans "No users linked." %}</p>
    {% endif %}
    {% include "oscar/dashboard/partials/pagination.html" %}

    <h1>{% trans "Update details" %}</h1>
    {% include 'oscar/dashboard/partials/form.html' %}
{% endblock dashboard_content %}
